/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.transformation.editor.views.figures;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

/**
 * @generated
 * 
 */
public class TransformationExecutionFigure extends RoundedRectangle {
	public static final org.eclipse.swt.graphics.Color ACTION_COLOR = new Color(
			null, 175, 178, 239);
	private Label tag = new Label("<<Transformation Execution>>");
	private Label nameLabel = new Label("TransExe");
	private Label descriptionLabel = new Label(ALL_RULE);
	private Figure body = new Figure();
	private static final int HEAD_HEIGHT = 15;
	private static final String SPECIFIED_RULE = "specified rule";
	private static final String ALL_RULE = "all rule";
	private static final int TAG_HEIGHT = 12;

	public TransformationExecutionFigure() {
		super();
		XYLayout xyL = new XYLayout();
		setLayoutManager(xyL);
		setOpaque(true);
		this.setCornerDimensions(new Dimension(20, 20));

		tag.setFont(FontConstant.STEREO_TYPE_LABEL);
		add(tag);

		// nameLabel.setOpaque(false);
		nameLabel.setFont(FontConstant.ARIAL_8_B);
		// nameLabel.setForegroundColor(ColorConstants.black);
		// nameLabel.setBackgroundColor(ColorConstants.white);
		add(nameLabel);

		descriptionLabel.setFont(FontConstant.ARIAL_8);
		add(descriptionLabel);

		FlowLayout bodyLayout = new FlowLayout();
		bodyLayout.setHorizontal(false);
		body.setLayoutManager(bodyLayout);
		body.setBorder(new MarginBorder(5));
		add(body);
	}

	public void setName(String name) {
		this.nameLabel.setText(name);
	}

	public void setDescription(boolean spcifiedRule) {
		if (spcifiedRule)
			descriptionLabel.setText(SPECIFIED_RULE);
		else
			descriptionLabel.setText(ALL_RULE);
	}

	public void setBounds(Rectangle rect) {
		super.setBounds(rect);
		tag.setSize(rect.width, TAG_HEIGHT);

		// set namelabel's size, it's on the top of figure
		nameLabel.setLocation(new Point(rect.x, rect.y + TAG_HEIGHT));
		nameLabel.setSize(rect.width, HEAD_HEIGHT);

		// set descriptionLabel's size and location, it's in the middle of
		// figure, between name and body
		descriptionLabel.setSize(rect.width, descriptionLabel
				.getPreferredSize().height);
		descriptionLabel.setLocation(new Point(rect.x, rect.y + HEAD_HEIGHT
				+ TAG_HEIGHT));

		// set body's size and locaiton, it's at the bottom of the figure
		int bodyHeight = HEAD_HEIGHT + descriptionLabel.getSize().height;
		body.setLocation(new Point(rect.x, rect.y + bodyHeight));
		body.setSize(rect.width, rect.height - bodyHeight);
	}

	public Figure getBody() {
		return body;
	}

	public void setTag(String s) {
		tag.setText(s);
	}
}
